//
//  PlayAudioManager.m
//  ShanMei
//
//  Created by huazi on 15/4/13.
//  Copyright (c) 2015年 huazi. All rights reserved.
//

#import "PlayAudioManager.h"
@interface PlayAudioManager()
@property (nonatomic)BOOL isPlaying;
@end
@implementation PlayAudioManager
+(PlayAudioManager *)sharePlayAudioManager{
    static PlayAudioManager *_playAudioManager =nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _playAudioManager =[[PlayAudioManager alloc] init];
    });
    return _playAudioManager;
}
- (instancetype)init {
    if (self =[super init]) {
        _isPlaying =NO;
    }
    return self;
}
-(void)play{
    
    if (!self.isPlaying) {
        self.isPlaying =YES;
        SystemSoundID soundID;
        NSString *soundFile = [[NSBundle mainBundle]
                               pathForResource:@"message" ofType:@"caf"];
        
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)
                                         [NSURL fileURLWithPath:soundFile]
                                         , &soundID);
        AudioServicesPlayAlertSound(soundID);
    }
    
    
    [self performSelector:@selector(endPlay) withObject:self afterDelay:1.0];
}
- (void)endPlay{
    _isPlaying =NO;
}
@end
